package com.gbits.app.finance.convert;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.gbits.app.finance.api.FinanceConvert;
import com.gbits.app.finance.api.ItemFinanceConvert;

public class MultiEmpCmpSubjectConvert extends ItemFinanceConvert {

	private FinanceConvert<String> debitEmpFinanceConvert;
	private FinanceConvert<String> creditEmpFinanceConvert;
	private FinanceConvert<String> debitCmpFinanceConvert;
	private FinanceConvert<String> creditCmpFinanceConvert;
	public FinanceConvert<String> getDebitEmpFinanceConvert() {
		return debitEmpFinanceConvert;
	}

	public void setDebitEmpFinanceConvert(
			FinanceConvert<String> debitEmpFinanceConvert) {
		this.debitEmpFinanceConvert = debitEmpFinanceConvert;
	}

	public FinanceConvert<String> getCreditEmpFinanceConvert() {
		return creditEmpFinanceConvert;
	}

	public void setCreditEmpFinanceConvert(
			FinanceConvert<String> creditEmpFinanceConvert) {
		this.creditEmpFinanceConvert = creditEmpFinanceConvert;
	}

	public FinanceConvert<String> getDebitCmpFinanceConvert() {
		return debitCmpFinanceConvert;
	}

	public void setDebitCmpFinanceConvert(
			FinanceConvert<String> debitCmpFinanceConvert) {
		this.debitCmpFinanceConvert = debitCmpFinanceConvert;
	}

	public FinanceConvert<String> getCreditCmpFinanceConvert() {
		return creditCmpFinanceConvert;
	}

	public void setCreditCmpFinanceConvert(
			FinanceConvert<String> creditCmpFinanceConvert) {
		this.creditCmpFinanceConvert = creditCmpFinanceConvert;
	}
	public String doConvert(Map<String, Object> map) {
		StringBuffer debit = new StringBuffer();
		StringBuffer credit = new StringBuffer();
		Map<String, Object> data = new HashMap<String, Object>();
		data.putAll(map);
		
		List<Map<String, Object>> paySubject = super.getPayList(map);
		List<Map<String, Object>> subjects = super.getSubjectList(map);
		// 科目列表
		for (int i=0; i<paySubject.size(); i++) {
			Map<String, Object> pay = paySubject.get(i);
			data.putAll(subjects.get(0));
			data.putAll(pay);
			
			Object cmpCreditValue = this.getCreditCmpFinanceConvert().doConvert(data);
			Object empCreditValue = this.getCreditEmpFinanceConvert().doConvert(data);
			
			Object cmpDebitValue = this.getDebitCmpFinanceConvert().doConvert(data);
			Object empDebitValue = this.getDebitEmpFinanceConvert().doConvert(data);
			
			if (null != cmpCreditValue) {
				if (credit.length() > 0) {
					credit.append("\r\n");
				}
				credit.append(cmpCreditValue.toString());
			}
			if (null != empCreditValue) {
				if (credit.length() > 0) {
					credit.append("\r\n");
				}
				credit.append(empCreditValue.toString());
			}
			
			if (null != cmpDebitValue) {
				if (debit.length() > 0) {
					debit.append("\r\n");
				}
				debit.append(cmpDebitValue.toString());
			}
			if (null != empDebitValue) {
				if (debit.length() > 0) {
					debit.append("\r\n");
				}
				debit.append(empDebitValue.toString());
			}
			
			
		}
		StringBuffer sb = new StringBuffer();
		sb.append(credit.toString());
		if (sb.length() > 0) {
			sb.append("\r\n");
		}
		sb.append(debit.toString());
		return sb.toString();
	}

	@Override
	public String getUsageInfo(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getSubjectDetail(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getDebitAmount(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getCreditAmount(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return null;
	}


}
